// api/device.ts
import apiClient from './index';

export interface DeviceData {
  name: string;
  type_id: number;
  family_id: string;
  meta?: Record<string, any>;
  state?: Record<string, any>;
}

export interface DeviceState {
  [key: string]: any;
}

export interface DeviceStateHistoryParams {
  start_time?: string;
  end_time?: string;
}

export const getDevices = () => {
  return apiClient.get('/devices');
};

export const getDeviceTypes = () => {
  return apiClient.get('/device-types');
};

export const createDevice = (deviceData: DeviceData) => {
  return apiClient.post('/devices', deviceData);
};

export const getDeviceDetails = (deviceId: string) => {
  return apiClient.get(`/devices/${deviceId}`);
};

export const deleteDevice = (deviceId: string) => {
  return apiClient.delete(`/devices/${deviceId}`);
};

export const updateDeviceState = (deviceId: string, state: DeviceState) => {
  return apiClient.patch(`/devices/${deviceId}/state`, { state });
};

export const getDeviceStateHistory = (deviceId: string, params: DeviceStateHistoryParams) => {
  return apiClient.get(`/devices/${deviceId}/state-history`, { params });
};
